package com.dlc.shop.dao;
import com.dlc.shop.common.bean.leaf.LeafAlloc;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author leaf
 */
public interface IDAllocMapper {

    /**
     * 获取所有的leaf_alloc
     * @return
     */
    @Select("SELECT biz_tag, max_id, step, update_time FROM tz_leaf_alloc")
    @Results(value = {
            @Result(column = "biz_tag", property = "bizTag"),
            @Result(column = "max_id", property = "maxId"),
            @Result(column = "step", property = "step"),
            @Result(column = "update_time", property = "updateTime")
    })
    List<LeafAlloc> getAllLeafAllocs();

    /**
     * 获取指定的leaf_alloc
     * @param tag
     * @return
     */
    @Select("SELECT biz_tag, max_id, step FROM tz_leaf_alloc WHERE biz_tag = #{tag}")
    @Results(value = {
            @Result(column = "biz_tag", property = "bizTag"),
            @Result(column = "max_id", property = "maxId"),
            @Result(column = "step", property = "step")
    })
    LeafAlloc getLeafAlloc(@Param("tag") String tag);

    /**
     * 更新指定的biz_tag
     * @param tag
     */
    @Update("UPDATE tz_leaf_alloc SET max_id = max_id + step WHERE biz_tag = #{tag}")
    void updateMaxId(@Param("tag") String tag);

    /**
     * 更新指定的biz_tag
     * @param leafAlloc
     */
    @Update("UPDATE tz_leaf_alloc SET max_id = max_id + #{step} WHERE biz_tag = #{bizTag}")
    void updateMaxIdByCustomStep(LeafAlloc leafAlloc);

    /**
     * 获取所有的biz_tag
     * @return
     */
    @Select("SELECT biz_tag FROM tz_leaf_alloc")
    List<String> getAllTags();

    /**
     * 更新max
     * @param tag
     */
    @Update("UPDATE tz_leaf_alloc SET max_id = 1 WHERE biz_tag = #{tag}")
    void updateMaxIdToStep(@Param("tag") String tag);
}
